package demo11;

public class test2 {
    public static void main(String[] args) {
        String str = "123456789";

        if (!str.matches("[1-9]\\d{0,9}")){
            System.out.println("数据格式有误");
        }else{
            System.out.println("数据格式正确");
            int number = 0;
            for (int i = 0; i < str.length(); i++) {
                int c = str.charAt(i) - '0';//获取的数字的码值减零的码数来获取int数据
                number = number * 10 + c;
            }
            System.out.println(number);
        }
    }
}
